package TemperaturePackage;

import squareBorderPackage.Square;
import be.kuleuven.cs.som.annotate.*;

/**
 * A class of exceptions signaling illegal temperatures for squares.
 * 
 * @version 1.0
 * @author Esther Alberts and Jessa Bekker
 * 
 */

public class IllegalTemperatureException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3830513910396553545L;

	/**
	 * Initialize this new illegal temperature exception with given temperature
	 * and given square.
	 * 
	 * @param temperature
	 *            The temperature for this new illegal temperature exception.
	 * @param square
	 *            The square for this new illegal temperature exception.
	 * @post The temperature of this new illegal temperature exception is the
	 *       same as the given temperature |new.getTemperature() == temperature
	 * @post The square for this new illegal temperature exception is the same
	 *       as the given square |new.getSquare() == square
	 * @post The message for this new illegal temperature exception will be 'The
	 *       temperature should be larger than the minimum temperature' if the
	 *       temperature is larger than the minimum temperature of the square
	 *       object, it will be 'The temperature should be smaller than the
	 *       maximum temperature' if the temperature is smaller than the maximum
	 *       temperature of the square object, and it will be 'The temperature
	 *       cannot be null' if the temperature is given as a null object.
	 * @effect This new illegal temperature exception has further no cause
	 *         |super()
	 */
	public IllegalTemperatureException(Temperature temperature, Square square) {
		this.temperature = temperature;
		this.square = square;
		String message = "";
		if (temperature == null)
			message = "The temperature cannot be null";
		else if (temperature.toUnit(TemperatureUnit.CELSIUS).getNumeral() < square
				.getMinTemperature().toUnit(TemperatureUnit.CELSIUS)
				.getNumeral())
			message = "The temperature should be larger than the minimum temperature";
		else if (temperature.toUnit(TemperatureUnit.CELSIUS).getNumeral() > square
				.getMaxTemperature().toUnit(TemperatureUnit.CELSIUS)
				.getNumeral())
			message = "The temperature should be smaller than the maximum temperature";
		this.message = message;
	}

	/**
	 * Return the message of this illegal temperature exception.
	 */
	@Basic
	@Immutable
	public String getMessage() {
		return message;
	}

	/**
	 * Variable registering a message of this illegal temperature exception.
	 */
	private final String message;

	/**
	 * Return the temperature of this illegal temperature exception.
	 */
	@Basic
	@Immutable
	public Temperature getTemperature() {
		return temperature;
	}

	/**
	 * Variable registering the temperature of this illegal temperature
	 * exception.
	 */
	private final Temperature temperature;

	/**
	 * Return the square of this illegal temperature exception.
	 */
	@Basic
	@Immutable
	public Square getSquare() {
		return square;
	}

	/**
	 * Variable referencing the square of this illegal temperature exception.
	 */
	private final Square square;

}
